#include "titlewgt.h"
#include <QVBoxLayout>
#include <QHBoxLayout>

titleWgt::titleWgt(QWidget *parent)
    : QWidget{parent}
{
    this->setFixedSize(1080,30);//设置窗口大小
//    this->setStyleSheet("background-color:transparent");
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_StyledBackground);

    iconLabel_ = new QLabel(this);
    closeBtn_ = new QPushButton(this);
    minBtn_ = new QPushButton(this);
    //设置控件大小
    iconLabel_->setFixedSize(100,30);
    closeBtn_ ->setFixedSize(30,30);
    minBtn_->setFixedSize(30,30);

    minBtn_->setObjectName("minBtn_");
    closeBtn_->setObjectName("closeBtn_");

    // 首先，创建一个QFont对象并设置字体为“幼圆”
    QFont font("幼圆", 12); // 第二个参数是字体大小

    // 然后，应用这个字体到你的标签
    iconLabel_->setFont(font);
    iconLabel_->setText(QString("PotPlayer"));

    iconLabel_->setStyleSheet("QLabel {"
                                 "    border: transparent;"
//                                 "    background-color: transparent;"
                                 "    background-repeat: no-repeat; "
                                 "    border:1px groove transparent;"
                                 "    border-radius:7px;"
                                 "    padding:2px 4px;"
//                                 "    background-size: cover;"
//                                 "    color: rgb(255,255,255);"
                                 "    color: rgb(0,0,0);"
                                 "}"
                             );


    // 当用户点击缩小按钮时，缩小窗口
    connect(minBtn_, &QPushButton::clicked, this, [this]()
    {
        this->parentWidget()->showMinimized();
    });

    //点击退出按钮，关闭主窗口
    connect(closeBtn_,&QPushButton::clicked,this, [this]()
    {
        this->parentWidget()->close();
    });

    //设置水平布局
    QHBoxLayout* hlayout = new QHBoxLayout(this);
    hlayout->addWidget(iconLabel_);
    hlayout->addStretch(1);//加弹簧
    hlayout->addWidget(minBtn_);
    hlayout->addWidget(closeBtn_);
    hlayout->setContentsMargins(0,0,0,0);
    //设置布局
    this->setLayout(hlayout);

}
